const o = {
  name: '张三',
  age: 17,
  height: 180
}

const template = `<div>我是{{ name }}, 我今年{{age}}, 身高： {{height}}</div>`

function replaceTemplate(template, o) {
  const regStr = Object.keys(o).map(key => {
    return `\{\{\\s*(${key})\\s*\}\}`
  }).join('|')

  const reg = new RegExp(regStr, 'g')
  console.log(reg)
  let index = 1;
  return template.replace(reg, (...arr) => {
   
    // return o[]
    return o[arr[index++]]
  })
  
}

const s= replaceTemplate(template, o)

console.log(s)